{{ define "admin/doc/index.html" }}
{{ template "public/header.html" .}}
<style>
    .el-card__body {
        padding: 5px !important;
    }
    .tox-tinymce {
        height: 500px !important;
    }
</style>
<div id="app" class="page-content" :style="!urlobj.dialogstate ? 'margin-top:50px;':'margin-top:10px;'">
    <tab-tag v-if="!urlobj.dialogstate"></tab-tag>
<div style="margin:5px 15px 15px 15px;">
    <el-card shadow="never" style="">
        <el-descriptions class="margin-top" :title="info.title" :column="3" size="small" border>
            <el-descriptions-item>
                <template slot="label">
                    文档数
                </template>
                {{ "{{info.total}}" }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    排序
                </template>
                {{ "{{info.sort}}" }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    是否首页显示
                </template>
                {{ "{{info.is_home ? '是':'否'}}" }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    知识库描述
                </template>
                {{ "{{info.desc}}" }}
            </el-descriptions-item>
        </el-descriptions>
        <el-row style="margin-top: 5px">
            <el-button v-if="checkPermission('/admin/doc/add')" size="small" icon="el-icon-plus" type="primary" @click="add" >添加目录</el-button>
            <a  href="/admin/book/index"><el-button type="info" size="small">关闭</el-button></a>
        </el-row>
    </el-card>
    <el-row :gutter="10">
        <el-col :span="5" class="hidden-sm-and-down">
            <left-tree :treelist="treeList" @update_info="update" @update_content="updateContent"  fieldname="id" @refesh_list="index"></left-tree>
        </el-col>
        <el-col :xs="23" :sm="23" :md="19" :lg="19">
            <el-card shadow="never" style="min-height:600px;">
                <div >
                    <Detail :info="detailInfo"  :show.sync="dialog.detailDialogStatus" ></Detail>
                </div>
            </el-card>
        </el-col>
    </el-row>
    <!--添加-->
    <Add :info="info" :show.sync="dialog.addDialogStatus"  @refesh_list="index"></Add>
    <!--修改-->
    <Update :info="updateInfo"  :show.sync="dialog.updateDialogStatus"  @refesh_list="index"></Update>
</div>
</div>
<script src="/static/admin/js/app.js"></script>
<script src="/static/admin/libs/treeselect/vue-treeselect.umd.min.js"></script>
<link rel="stylesheet" href="/static/admin/libs/treeselect/vue-treeselect.min.css">
<script src="/static/admin/editor/tinymce/tinymce.min.js"></script>
<script src="/static/components/admin/doc/add.js?v={{.v}}"></script>
<script src="/static/components/admin/doc/update.js?v={{.v}}"></script>
<script src="/static/components/admin/doc/detail.js?v={{.v}}"></script>
<script>
    new Vue({
        el: '#app',
        components:{
        },
        data: function() {
            return {
                dialog: {
                    addDialogStatus : false,
                    updateDialogStatus : false,
                    detailDialogStatus : true,
                },
                loading: false,
                treeList:[],
                order:'',
                sort:'',
                ids: [],
                single:true,
                multiple:true,
                left_expand:true,
                list: [],
                updateInfo:{},
                detailInfo:{},
                info:{},
                book_id:'',
            }
        },
        methods:{
            index(){
                let param = {id:this.book_id}
                axios.post(base_url + '/admin/book/getUpdateInfo',param).then(res => {
                    if(res.data.status == 200){
                        this.info = res.data.data
                        this.loading = false
                        axios.post(base_url + '/admin/doc/list',{book_id:this.book_id}).then(res1 => {
                            if(res1.data.status == 200){
                                this.treeList = res1.data.data.data
                                this.info.total = res1.data.data.total
                            }else{
                                this.$message.error(res1.data.msg);
                            }
                        })
                    }else{
                        this.$message.error(res.data.msg);
                    }
                })
            },
            add(){
                axios.post(base_url + '/admin/book/getUpdateInfo',{id:this.info.id}).then(res => {
                    if(res.data.status == 200){
                        this.dialog.addDialogStatus = true
                        this.updateInfo = res.data.data
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            },
            update(row){
                let id = row.row.val
                axios.post(base_url + '/admin/doc/getUpdateInfo',{id:id}).then(res => {
                    if(res.data.status == 200){
                        this.dialog.updateDialogStatus = true
                        this.updateInfo = res.data.data
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            },
            updateContent(row){
                this.dialog.detailDialogStatus = false
                let id = row.row.val
                axios.post(base_url + '/admin/doc/getUpdateInfo',{id:id}).then(res => {
                    if(res.data.status == 200){
                        this.dialog.detailDialogStatus = true
                        this.detailInfo = res.data.data
                        console.log(this.detailInfo)
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            },
            del(row){
                this.$confirm('确定操作吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let ids = row.id ? row.id : this.ids.join(',')
                    axios.post(base_url + '/admin/doc/delete',{id:ids}).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.index()
                        }else{
                            this.$message.error(res.data.msg)
                        }
                    })
                }).catch(() => {})
            },
            selection(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length != 1
                this.multiple = !selection.length
            },
            handleRowClick(row, rowIndex,event){
                if(event.target.className !== 'el-input__inner'){
                    this.$refs.multipleTable.toggleRowSelection(row)
                }
            },
            rowClass ({ row, rowIndex }) {
                for(let i=0;i<this.ids.length;i++) {
                    if (row.id === this.ids[i]) {
                        return 'rowLight'
                    }
                }
            },
            submit(){
                this.$refs['form'].validate(valid => {
                    if(valid) {
                        this.loading = true
                        axios.post(base_url + '/admin/doc/update',this.form).then(res => {
                            if(res.data.status == 200){
                                this.$message({message: res.data.msg, type: 'success'})
                                this.closeForm()
                            }else{
                                this.loading = false
                                this.$message.error(res.data.msg)
                            }
                        }).catch(()=>{
                            this.loading = false
                        })
                    }
                })
            },
            urlArgumentsFun(url){
                const obj = {};
                const arr = url.split('?')[1].split("&");
                arr.forEach(element => {
                    const args = element.split("=");
                    obj[args[0]] = args[1];
                });
                return obj;
            },
            fn(method){
                this[method](this.ids)
            },
        },
        mounted(){
            var currentUrl = document.URL;
            var param = this.urlArgumentsFun(currentUrl)
            this.book_id = param.book_id
            this.index()
        },
    })
</script>
{{ template "public/footer.html" .}}
{{ end }}